<?php

class IndentedTextWriter
{
    const ForWriting = 'w';
    
    public function __construct(
        $indent = 0, $newLine = PHP_EOL, $tabString = '    ')
    {
        $this->Indent = $indent;
        $this->NewLine = $newLine;
        $this->TabString = $tabString;
    }
    
    protected function outputTabs()
    {
        if($this->TabsPending)
        {
            $this->InnerString .= str_repeat($this->TabString, $this->Indent);
        }
        
        $this->TabsPending = false;
    }
    
    public function clear()
    {
        $this->InnerString = '';
    }
    
    public function write($value)
    {
        $this->OutputTabs();
        $this->InnerString .= (string)$value;
    }
    
    public function writeLine($value = '')
    {
        $this->write($value);
        $this->InnerString .= PHP_EOL;
        $this->TabsPending = true;
    }
    
    public function get_NewLine()
    {
        return $this->NewLine;
    }

    public function set_NewLine($NewLine)
    {
        if(is_string($NewLine))
        {
            $this->NewLine = $NewLine;
        }
        else
        {
            throw new InvalidArgumentException(
                'The value must be a string.');
        }
    }

    public function get_TabString()
    {
        return $this->TabString;
    }

    public function set_TabString($TabString)
    {
        if(is_string($TabString))
        {
            $this->TabString = $TabString;
        }
        else
        {
            throw new InvalidArgumentException(
                'The value must be a string.');
        }
    }
    
    public function get_String()
    {
        return $this->InnerString;
    }
    
    public $Indent;
    protected $NewLine;
    protected $TabString;
    protected $TabsPending = true;
    
    protected $InnerString;
}

?>
